﻿using Cache.CSRedis;
using Microsoft.Extensions.Hosting;
using Order.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace OrderWebApi
{
    public class InitRedisBackgroundService : BackgroundService
    {
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await Task.Factory.StartNew(async () =>
             {
                 List<RedisOptions> redisOptions = new List<RedisOptions>()
                 {
                      new RedisOptions
                        {
                            HostName = "127.0.0.1",
                            Port = 6379,
                            Password = "abcdefg123456",
                            DefaultDatabase = string.Empty,
                            WriteBuffer = 10240,
                            Prefix = string.Empty,
                            TryIt = 3,
                            PoolSize = 50,
                            SSL = false,
                            ExpireSeconds = 60,
                            EnvName = string.Empty
                        },
                      new RedisOptions
                        {
                            HostName = "47.104.83.210",
                            Port = 6379,
                            Password = "abcdefg123456",
                            DefaultDatabase = string.Empty,
                            WriteBuffer = 10240,
                            Prefix = string.Empty,
                            TryIt = 3,
                            PoolSize = 50,
                            SSL = false,
                            ExpireSeconds = 60,
                            EnvName = string.Empty
                        }
                 };
                 RedisConcurrentDictionary.InitRedisInstance(redisOptions);
                 await Task.CompletedTask;
             });
        }
    }
}
